<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>固定定位</title>
    <style>
        body{
            padding: 0;
            margin: 0;
            height: 2000px;
            /* background: #0f0; */
        }
        #div1{
            width: 100%;
            height: 50px;
            background: #f00;
            margin: 0;
            position: fixed;
            padding: 0 20px;
        }
    </style>
</head>
<body>
    <div id="div1">导航栏</div>
</body>
</html>